package sysu.el.matrix.ints;

public class MatInt {
	public int w[][];
	
	public MatInt(){
		
	}
	
	public MatInt(int num1, int num2){
		w = new int[num1][num2];
	}
	
	public MatInt(int num){
		w = new int[num][num];
	}
	
	public static void copy(int[][] src, int[][] dst, int offset){
		for (int i=0; i<src.length; i++)
			for (int j=0; j<src[i].length; j++){
				dst[i+offset][j+offset] = src[i][j];
			}
	}
	
	public static void add(int[][] src, int[][] dst, int offset){
		for (int i=0; i<src.length; i++)
			for (int j=0; j<src[i].length; j++){
				dst[i+offset][j+offset] += src[i][j];
			}
	}
	
	public static void copy(int[][] src, int[][] dst, int rowoff, int rowdis, int coloff, int coldis){
		int rowID = rowoff;
		for (int i=0; i<src.length; i++){
			int colID = coloff;
			for (int j=0; j<src[i].length; j++){
				dst[rowID][colID] = src[i][j];
				colID += coldis;
			}
			rowID += rowdis;
		}
	}
	
//	public static void boom(int[][] src, int row, int col){
//		int dst[][] = new int[src.length+]
//	}
	
    /**
     * Builds a completely unconnected (edge-free) graph with the given 
     * number of nodes
     * @param n the number of nodes
     * @return a graph with n nodes and no edges
     */
    public static int[][] buildPhalanx(int n) {
    	int a[][] = new int[n][n];
//    	for (int i=0; i<n; ++i)
//    		for (int j=0; j<n; ++j)
//    			a[i][j] = 0;
    	return a;
    }
    
    /**
     * Builds a completely unconnected (edge-free) graph with the given 
     * number of nodes
     * @param n the number of nodes
     * @return a graph with n nodes and no edges
     */
    public static int[][] buildMatrix(int n, int n1) {
    	int a[][] = new int[n][n1];
//    	for (int i=0; i<n; ++i)
//    		for (int j=0; j<n; ++j)
//    			a[i][j] = 0;
    	return a;
    }
    
	public static void drawEdges(int[][] g, int num, int chain[], int val){
		for (int i=0; i<num-1; i++){
			g[chain[i]][chain[i+1]] = val;
			g[chain[i+1]][chain[i]] = val;
		}
	}
	
	public static void drawEdges(int[][] g, int num, int chain[]){
		MatInt.drawEdges(g, num, chain, 1);
	}
	
	public static void drawEdges(int[][] g, int chain[]){
		MatInt.drawEdges(g, chain.length, chain);
	}
	
	public static int symetrical(int[][] g){
		int edgeNum = 0;
		for (int i=0; i<g.length; i++)
			for (int j=0; j<g[i].length; j++){
				if ((g[i][j] | g[j][i]) == 1){
					g[i][j] = 1;
					g[j][i] = 1;
					edgeNum ++;
				}else{
					g[i][j] = 0;
					g[j][i] = 1;
				}
			}
		return edgeNum;
	}
	
	public static int isSymetrical(int[][] g){
		int edgeNum = 0;
		for (int i=0; i<g.length; i++)
			for (int j=0; j<g[i].length; j++){
				if ((g[i][j] | g[j][i]) == 1){
					g[i][j] = 1;
					g[j][i] = 1;
					edgeNum ++;
				}else{
					g[i][j] = 0;
					g[j][i] = 1;
				}
			}
		return edgeNum;
	}
	
	public static void getSubMatrix(int[][] src, int idx_len, int idx[], int dst[][]){
		for (int i=0; i<idx_len; i++){
			for (int j=0; j<idx_len; j++)
				dst[i][j] = src[idx[i]][idx[j]];
		}
	}
	
	public static int[][] getSubMatrix(int[][] src, int idx_len, int idx[]){
		int[][] dst = new int[idx_len][idx_len];
		MatInt.getSubMatrix(src, idx_len, idx, dst);
		return dst;
	}
	
}
